<?php

/*
Plugin Name: ACCS Alex Sandbox
Version: .1
Plugin URI: https://code.google.com/p/rollins-capstone-project/
Description: Alex's Sandbox for ACCS Rollins Capstone Project
Author: Alex Concha
Author URI: http://alexconcha.com
*/

/*
	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.
*/

if (!class_exists('ACCSAlexPlugin')) {

class ACCSAlexPlugin
{
    public function __construct() {
        add_action('init', array(&$this, 'accs_register_post_types'));
        add_action('init', array(&$this, 'accs_register_taxonomies'));
    }

    // called when plugin is activated
    public function accs_activate() {
        // register custom types
        $this->accs_register_post_types();

        // register custom taxonomies
        $this->accs_register_taxonomies();
        $this->accs_populate_taxomies();

        //flush stuff
        flush_rewrite_rules();
    }

    // called when plugin is deactivated
    public function accs_deactivate() {
        // un-register custom types

        // register custom taxonomies
    }

    // called when plugin is uninstalled
    public function accs_uninstall($echo=false) {
       // if we had tables this is where we nuke em
    }

    public function accs_register_post_types()
    {
        $supports = array(
            'title',
            'editor',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'revisions',
            'page-attributes'
        );

        register_post_type( 'accs_event',
            array(
                'labels' => array(
                    'name' => __( 'Events' ),
                    'singular_name' => __( 'Event' )
                ),
                'public' => true,
                'has_archive' => true,
                'supports' => $supports,
                'taxonomies' => array('category')
            )
        );

        register_post_type( 'accs_promo',
            array(
                'labels' => array(
                    'name' => __( 'Special Promotions' ),
                    'singular_name' => __( 'Special Promotion' )
                ),
                'public' => true,
                'supports' => $supports,
                'taxonomies' => array('category')
            )
        );

        register_post_type( 'accs_announcement',
            array(
                'labels' => array(
                    'name' => __( 'Announcements' ),
                    'singular_name' => __( 'Announcement' )
                ),
                'public' => true,
                'has_archive' => true,
                'supports' => $supports,
                'taxonomies' => array('category')
            )
        );
    }

    public function accs_register_taxonomies()
    {
        register_taxonomy('audience'
            ,array('accs_event', 'accs_promo', 'accs_announcement', 'post')
            ,array(
                'hierarchical' => true,
                'label' => __( 'Audience' ),
                'sort' => true,
                'args' => array( 'orderby' => 'term_order' ),
                'rewrite' => array( 'slug' => 'audience' ),
            )
        );
    }

    function accs_populate_taxomies()
    {
        if(!term_exists( 'faculty', 'audience' ))
        {
            wp_insert_term(
                'Faculty', // the term
                'audience', // the taxonomy
                array(
                    'description'=> 'Zee Faculty',
                    'slug' => 'faculty'
                )
            );
        }

        if(!term_exists( 'student', 'audience' ))
        {
            wp_insert_term(
                'Student', // the term
                'audience', // the taxonomy
                array(
                    'description'=> 'Zee Wildpeople',
                    'slug' => 'students'
                )
            );
        }

        if(!term_exists( 'sports', 'category' ))
        {
            wp_insert_term(
                'Sports', // the term
                'category', // the taxonomy
                array(
                    'description'=> 'Balls',
                    'slug' => 'sports'
                )
            );
        }
    }

} // end of class
} // end of class exists if

if( class_exists( 'ACCSAlexPlugin' ) ) {
    $cn = new ACCSAlexPlugin;
    // Register for activation
    register_activation_hook( __FILE__, array( &$cn, 'accs_activate' ));
    register_deactivation_hook( __FILE__, array( &$cn, 'accs_deactivate' ));
    register_uninstall_hook( __FILE__, array( &$cn, 'accs_uninstall' ));
}
